<?php

/**
 * maincourante actions.
 *
 * @package    mercure
 * @subpackage maincourante
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class maincouranteActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->setLayout('layout_sansfen'); // on utilise le layout ou la fenetre n'apparait pas
    $this->main_courante_evenements = MainCouranteEvenementTable::getMainCourante();
    $this->maincourante = new MainCouranteEvenement();
        
    $this->form = new MainCouranteEvenementForm();
    
    $this->pager = new sfDoctrinePager(
      'MainCouranteEvenement',
      sfConfig::get('app_max_item_maincourante')
    );
    $this->pager->setQuery($this->maincourante->getQueryMainCourante());
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->main_courante_evenement = Doctrine_Core::getTable('MainCouranteEvenement')->find(array($request->getParameter('idmaincour')));
    $this->forward404Unless($this->main_courante_evenement);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new MainCouranteEvenementForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new MainCouranteEvenementForm();

    $this->processForm($request, $this->form);
            
    $this->redirect('maincourante/index');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($main_courante_evenement = Doctrine_Core::getTable('MainCouranteEvenement')->find(array($request->getParameter('idmaincour'))), sprintf('Object main_courante_evenement does not exist (%s).', $request->getParameter('idmaincour')));
    $this->form = new MainCouranteEvenementForm($main_courante_evenement);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($main_courante_evenement = Doctrine_Core::getTable('MainCouranteEvenement')->find(array($request->getParameter('idmaincour'))), sprintf('Object main_courante_evenement does not exist (%s).', $request->getParameter('idmaincour')));
    $this->form = new MainCouranteEvenementForm($main_courante_evenement);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($main_courante_evenement = Doctrine_Core::getTable('MainCouranteEvenement')->find(array($request->getParameter('idmaincour'))), sprintf('Object main_courante_evenement does not exist (%s).', $request->getParameter('idmaincour')));
    $main_courante_evenement->delete();

    $this->redirect('maincourante/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    
    if ($form->isValid())
    {
      $main_courante_evenement = $form->save();

      $this->redirect('maincourante/index');
    }
  }
}
